<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<!DOCTYPE>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>社区帖子列表页面</title>
    <c:import url="common.jsp"></c:import>
    <script>
        function myselect(obj) {
            console.log(obj);
            //判断当前复选框是否是选中的
            if (obj.checked == true) {//如果当前复选框选中，则所有下面的选择框都选中
                //$("[name='ids']").attr("checked","checked");
                $("[name='ids']").prop("checked", true);
            } else {
                //$("[name='ids']").attr("checked","");//这个不生效
                $("[name='ids']").prop("checked", false);
            }
        }
    </script>
</head>
<body>
<c:import url="nav.jsp"></c:import>

<div style="margin: 0 10%">
    <form action="delete.action" method="post">
        <table class="table table-hover">
            <tr>
                <th><input type="checkbox" onclick="myselect(this)"/></th>
                <th>编号</th>
                <th>标题</th>
                <th>作者</th>
                <th>点赞数</th>
                <th>发布时间</th>
                <th>操作</th>
            </tr>
            <c:forEach var="inv" items="${list }">
                <tr class="active">
                    <td><input name="ids" type="checkbox" value="${inv.id }"/></td>
                    <td>${inv.id }</td>
                    <td><a href="findbyid.action?id=${inv.id }">${inv.title }</a></td>
                    <td>${inv.name }</td>
                    <td style="font-weight: bolder;color: red">${inv.likes }</td>
                    <td><fmt:formatDate value="${inv.createdate }" pattern="yyyy-MM-dd HH:mm"></fmt:formatDate></td>
                    <td>
                        <button onclick="javascript:location.href='findbyid.action?id=${inv.id }'"
                                type="button" class="btn btn-info btn-sm">DETAIL
                        </button>
                        <c:if test="${currentUser.uid==inv.uid}">
                            <button onclick="javascript:location.href='update.action?id=${inv.id }'"
                                    type="button" class="btn btn-primary btn-sm">UPDATE
                            </button>

                            <button onclick="javascript:location.href='delete.action?ids=${inv.id }'"
                                    type="button" class="btn btn-danger btn-sm">DELETE
                            </button>
                        </c:if>
                    </td>
                </tr>
            </c:forEach>
            <c:if test="${currentUser!=null}">
                <tr align="center">
                    <td colspan="10">
                        <button onclick="javascript:location.href='add.action'"
                                type="button" class="btn btn-info">ADD
                        </button>
                        <c:if test="${currentUser.rid==2}">
                            <button type="submit" class="btn btn-danger">DELETE</button>
                            <%--                            <input value="删除" type="submit"/>--%>
                        </c:if>
                    </td>
                </tr>
            </c:if>
        </table>
    </form>
</div>
</body>
</html>